# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=gitoxide
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.44.0
pkgrel=2
pkgdesc="An idiomatic, lean, fast & safe pure Rust implementation of Git (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="https://github.com/GitoxideLabs/gitoxide"
license=('spdx:Apache-2.0 OR MIT')
msys2_references=(
  'archlinux: gitoxide'
  'purl: pkg:cargo/gitoxide'
)
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" 'git')
source=("git+${url}.git#tag=v${pkgver}")
sha256sums=('caa76f7912fdc57c96468b3ed958422d2765dd0101179902173f2bcef3992f01')

prepare() {
  cd "${_realname}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  cargo build \
    --release \
    --locked \
    --no-default-features \
    --features max-pure \
    --bin gix \
    --bin ein
}

check() {
  cd "${_realname}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  cargo test \
    --release \
    --locked \
    --no-default-features \
    --features max-pure \
    --bin gix \
    --bin ein
}

package() {
  for _bin in gix ein; do
    install -Dm755 -t "${pkgdir}${MINGW_PREFIX}/bin" "${_realname}/target/release/${_bin}"

    # install completions
    local _complete="${pkgdir}${MINGW_PREFIX}/bin/${_bin} completions -s"
    $_complete bash | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/${_bin}"
    $_complete zsh | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_${_bin}"
    $_complete fish | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/${_bin}.fish"
  done

  install -Dm644 "${_realname}"/LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
